
<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>{{config("site.title")}}</title>
    <link rel="stylesheet" type="text/css" href="css/css.css">
    <link rel="stylesheet" type="text/css" href="{{asset('/dhtmlgoodies_calendar/dhtmlgoodies_calendar.css')}}">
    <div id="wx_logo" style="display: none">
        <img src="{{asset('image/weixin.jpg')}}">
    </div>
</head>

<body>
<div class="banner"><img src="image/pc_banner.jpg"></div>
<div class="partner_1">
    <p>上传作品</p>
        <table>
            <tbody>
            <tr>
                <td align="right">作品名称<span>*</span></td>
                <td><input id="name" type="text" class="text" data-msg-required=""></td>
            </tr>
            <tr>
                <td align="right">拍摄地点<span>*</span></td>
                <td><input id="pic_address" type="text" class="text" data-msg-required=""></td>
            </tr>
            <tr>
                <td align="right">拍摄时间<span>*</span></td>
                <td><input id="add_time" type="text" class="text" onfocus="displayCalendar(this, 'yyyy-mm-dd', this, true)"></td>
            </tr>
            <tr>
                <td align="right">上传作品<span>*</span></td>
                <td>
                    <a href="javascript:;" id="pickfiles" class="pickfiles" title="选择图片">
                        <input id="pic" type="hidden" value="{{isset($key) ? $key :""}}"/>
                        <img style="width: 80px;" src="/img/{{$type}}-{{isset($key) ? $key :""}}/{{$value}}" onerror="this.src='{{url("images/defaltPic.jpg")}}'"/>
                    </a>
                    {{--<input type="button" name="email" class="file" value="选择图片">--}}
                </td>
            </tr>
            <tr>
                <td align="right">作者姓名<span>*</span></td>
                <td><input id="author" type="text" class="text" data-msg-required=""></td>
            </tr>
            <tr>
                <td align="right">作者地址<span>*</span></td>
                <td><input id="authoraddress" type="text" class="text" data-msg-required=""></td>
            </tr>
            <tr>
                <td align="right">手机号<span>*</span></td>
                <td><input id="mobile" type="text" class="text" data-msg-required=""></td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                    <input id="confirm" type="submit" class="btn" value="确定">
                </td>
            </tr>
            </tbody>
        </table>
</div>
</body>
<script src="{{asset('/dhtmlgoodies_calendar/dhtmlgoodies_calendar.js')}}" type="text/javascript"></script>
<script src="{{asset('/js/jquery-1.9.1.js')}}" type="text/javascript"></script>
<script src="{{ asset('/js/plupload/plupload.full.min.js') }}"></script>
<script type="text/javascript" language="JavaScript">

    $(function () {
        var uploader = new plupload.Uploader({
            runtimes: 'html5,flash,silverlight,html4',
            url: "{{ url('upimg') }}",
            browse_button: 'pickfiles', // you can pass in id...
            //container: document.getElementById('container'), // ... or DOM Element itself
            max_file_size: '20mb',
//            chunk_size : '1mb',
            filters: {
                mime_types: [
                    {title: "Image files", extensions: "jpg,gif,png"}
                ]
            },
            multi_selection: false,
            file_data_name: 'file',
            multipart_params: {'_token': '{{ csrf_token() }}', 'dir': '{{$type}}'},
            // Flash settings
            flash_swf_url: '{{ asset("js/plupload/Moxie.swf") }}',
            // Silverlight settings
            silverlight_xap_url: '{{ asset('js/plupload/Moxie.xap') }}',
            init: {
                PostInit: function () {
                    return false;
                },
                FilesAdded: function (up, file) {
                    $('.pickfiles img').attr('src', '{{ asset('images/loading.gif') }}');
                    uploader.start();
                },
                Error: function (up, err) {
                    alert("Error" + err.message);
                },
                FileUploaded: function (up, file, responseObj) {
                    var response = $.parseJSON(responseObj.response);
                    if (response.state == 'success') {
                        __type = "{{$type}}";
                        $('.pickfiles img').attr('src', '{!! url("img/'+__type+'-' + response.id + '/290-165") !!}');
                        $('.pickfiles input').val(response.id);
                    } else {
                        alert("FileUploadedError:" + response.message);
                    }
                }
            }
        });
        uploader.init();


        //上传作品
        $("#confirm").on("click", function(){
            if('' == $("#name").val()){
                alert("请填写作品名称");
                return;
            }
            if('' == $("#pic_address").val()){
                alert("请填写拍摄地点");
                return;
            }
            if('' == $("#add_time").val()){
                alert("请填写拍摄时间");
                return;
            }
            if('' == $("#pic").val()){
                alert("请上传作品");
                return;
            }
            if('' == $("#author").val()){
                alert("请作者姓名");
                return;
            }
            if('' == $("#authoraddress").val()){
                alert("请填写作者地址");
                return;
            }
            if('' == $("#mobile").val()){
                alert("请填写手机号");
                return;
            }
            if('' == $("#name").val()){
                alert("请填写作品名称");
                return;
            }

            var postData = {
                name:$("#name").val(),
                pic_address:$("#pic_address").val(),
                add_time:$("#add_time").val(),
                add_month:$("#add_month").val(),
                pic:$("#pic").val(),
                author:$("#author").val(),
                authoraddress:$("#authoraddress").val(),
                mobile:$("#mobile").val(),
                _token:"{{ csrf_token() }}"
            };
            $.ajax({
                type:"POST",
                url:"{{url('uploadwork')}}",
                async:true,
                headers:{  },
                data:postData
            }).done(function(data){

                alert(data.message);
                if('success' == data.state){
                    window.location.href = '{{url('index')}}';
                }
            }).fail(function(){

            }).always(function(data){
                alert(data.message);
            });
        });
    });
</script>
</html>